package com.sky.mapper;


import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrderMapper {
    /**
     * 插入订单数据
     * @param orders
     */
    void insert(Orders orders);

    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);


    /**
     * 订单分页查询
     * @param ordersPageQueryDTO
     * @return
     */
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 根据订单id查询订单
     * @param id
     */

    @Select("select * from orders where id = #{id}")
    Orders getById(Long id);


    /**
     * 根据状态统计订单数量
     *
     */
    @Select("select count(id) from orders where status = #{status}")
    Integer countStatus(Integer confirmed);

    /**
     * 查询订单
     * @return
     */
    @Select("select * from orders where status = #{pendingPayment} and order_time < #{now}")
    List<Orders> removeTimeoutOrders(Integer pendingPayment, LocalDateTime now);

    /**
     * 统计营业额
     * @param begin
     * @param end
     * @return
     */
    @Select( "select sum(amount) from orders where order_time between #{begin} and #{end} and status = #{status}")
    Double sumByMap(LocalDateTime begin, LocalDateTime end, Integer status);

    /**
     * 统计订单数量
     * @param begin 时间开始
     * @param end 时间结束
     * @param status 订单状态
     */
    Integer OrdercountByDate(LocalDateTime begin, LocalDateTime end, Integer status);

    /**
     * 查询销量排名top10
     * @param begin
     * @param end
     * @return
     */
    List<GoodsSalesDTO> getSalesTop10(LocalDateTime begin, LocalDateTime end);
}
